const app = getApp()
import {
  reqGetNoticeListByType
} from '../../../../../request/api.js'
import {
  showMsg
} from '../../../../../utils/config.js'

Component({

  properties: {

  },

  options: {
    addGlobalClass: true
  },

  data: {
    navHeight: app.globalData.navHeight + 'px', //头部距离
    bottomHeight: app.globalData.bottomHeight + 'px', //iphone底部距离

    page: 1,
    limit: 10,
    dataList: [],
    triggered: false, //是否下拉刷新列表
    isNextPage: true,
  },

  pageLifetimes: {
    async show() {
      this.setData({
        familyInfo: app.globalData.familyInfo
      })
      this.getDataList()
      if (this.data.isUpdataList || app.globalData.isUpdateCIndex) {

        this.setData({
          isUpdataList: false
        })
        app.globalData.isUpdateCIndex = false
        wx.setStorageSync('isUpdateCIndex', false);
      }
    },
  },


  methods: {
    // 滚动到底部触发
    alarmLower() {
      if (!this.data.isNextPage) return
      this.setData({
        page: this.data.page + 1,
      })
      this.getDataList()
    },
    // 下拉刷新
    async alarmRefresh() {
      this.setData({
        dataList: [],
        page: 1,
        isNextPage: true,
        triggered: true,
      })
      await this.getDataList()
      this.setData({
        triggered: false,
      })
    },
    // 告警列表
    async getDataList() {
      const res = await reqGetNoticeListByType(this.data.page, this.data.limit, {
        userId: app.globalData.userId,
        noticeType:'3'
      })
      if (res.code !== 20000) return showMsg(res.message)
      console.log(res,'设备');
      let {
        rows
      } = res.data
      if (this.data.page === 1) {
        this.setData({
          dataList: rows,
          isNextPage: rows.length >= this.data.limit
        })
      } else if (rows.length) {
        this.setData({
          dataList: this.data.dataList.concat(rows),
          isNextPage: rows.length >= this.data.limit
        })
      } else {
        this.setData({
          isNextPage: false
        })
      }
    },
  }
})